package com.ruoyi.inspection.domain.receiveVo;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.constant.GlobalConstants;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.inspection.config.JobBillTypeEnum;
import com.ruoyi.inspection.config.JobStatusEnum;
import com.ruoyi.inspection.constant.InspectionConstant;
import com.ruoyi.system.domain.AppCreateJobBill;
import com.ruoyi.system.domain.JobPlanBillDeclare;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;
import java.util.UUID;

/**
 * 上报 特殊作业票证信息
 */
@Data
public class ReceiveJobTicketVideo implements Serializable {
    //// 唯一编码，36 位uuid，必填
    private String id;
    private String workorderId;
    //企业编码
    private String companyCode;
    //作业类型
    private String videoCode;
    // 删除状态
    private String deleted;
    private String createBy;
    private String updateBy;
//    private String createDate;
//    private String updateDate;
    private String createTime;
    private String updateTime;


    /**
     * 构建作业票对象
     * @param jobBill
     * @return
     */
    public static ReceiveJobTicketVideo convertAppCreateJobBill(AppCreateJobBill jobBill) {
        String workOrderId = jobBill.getGovernId();
        if (StringUtils.isEmpty(workOrderId)) {
            return null;
        }

        String governVideoId = jobBill.getGovernVideoId();
        governVideoId = StringUtils.isEmpty(governVideoId) ? UUID.randomUUID().toString() : governVideoId;
        Date updateDate = jobBill.getModifyDate()==null ? jobBill.getCreatedDate() : jobBill.getModifyDate();
        String updateDateStr = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", updateDate);

        ReceiveJobTicketVideo jobVo = new ReceiveJobTicketVideo();
        jobVo.setId(governVideoId);
        jobVo.setWorkorderId(workOrderId);
        jobVo.setCompanyCode(GlobalConstants.COMPANY_CODE);
        jobVo.setVideoCode(InspectionConstant.VIDEO_CODE);
        jobVo.setDeleted("0");
        jobVo.setCreateTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", jobBill.getCreatedDate()));
        jobVo.setCreateBy(StringUtils.isEmpty(jobBill.getCreatedBy()) ? "admin" : jobBill.getCreatedBy());
        jobVo.setUpdateTime(updateDateStr);
        jobVo.setUpdateBy(jobBill.getModifyBy()==null ? "admin" : jobBill.getModifyBy());

        jobBill.setGovernVideoId(governVideoId);
        return jobVo;
    }


}
